home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
TCL1
/
MIDI_MAN
/
CMIDICLI.C
< prev
next >
Wrap
Text File
|
1992-03-07
|
4KB
|
124 lines
//--- CMIDIClient.c ---------------------------------------------------------------------
// Copyright ⌐ Paul Ferguson, 1990, 1991, 1992. All rights reserved.
//
// Superclass: CObject
// Subclasses: None
//
// Description:
// CMIDIClient.c defines a MIDI Manager client object.
//
// For use with THINK C 5.0, the accompanying THINK Class Library (TCL), and MIDI
// Manager 2.0. Refer to the accompanying Microsoft Word document for complete
// details about MIDI Manager objects.
//
// If you have comments or questions about this code, you can reach me on
// CompuServe at 70441,3055.
//
//--------------------------------------------------------------------------------------
//---- NOTE --- NOTE --- NOTE --- NOTE --- NOTE --- NOTE --- NOTE --- NOTE --- NOTE ----
//--------------------------------------------------------------------------------------
// If you are not familiar with programming the Apple MIDI Manager, refer to the
// "MIDI Management Tools" Version 2.0, available from APDA. You MUST have the
// software (MIDI.H and the library) from this package in order to use these objects.
// It will not work without this.
//--------------------------------------------------------------------------------------
// REVISION HISTORY:
// August ??, 1990 - Original release (1.0).
// November 5, 1990 - Added checks for midiMgrVer to most methods.
// August 1991 - updated for THINK C 5.0 as version 2.0
//--------------------------------------------------------------------------------------
#include "CMIDIClient.h" // This code's header file
extern OSType gSignature; // Used to register client
//--- gMIDIClient (global variable) --------------------------------------
// Because these objects are designed only for a single MIDI client, we
// define this global to hold it.
//------------------------------------------------------------------------
CMIDIClient * gMIDIClient = (CMIDIClient *) 0;
//--- CMIDIClient::IMIDIClient -------------------------------------------
// Initialize this object.
//
// Sign into the MIDI Manager. Save the midiMgrVerNum. It signs
// in with the application's name, and tries to find it's BNDL type.
//
// NOTE: Only one instance of a MIDI Manager Client can be made, with
// the current design of these objects. Other methods assume
// that the 'gMIDIClient' variable points to a valid instance
// of this type.
//------------------------------------------------------------------------
OSErr CMIDIClient::IMIDIClient(short theIconID)
{
OSErr err;
Handle theIconHndl; // Used by MIDISignIn
Str255 theName; // me too...
short i; // Junk variables
Handle h;
// Make sure MIDIMgr is installed and save version num.
midiMgrVerNum = SndDispVersion(midiToolNum);
if (midiMgrVerNum == 0) // Damn! Things were going so well...
{
return ErrNoMIDI; // No MIDI driver seems to be loaded
}
//--- Sign in to the MIDI Manager. -------------------------------
theIconHndl = GetResource('ICN#',theIconID); // Let's get our icon
CheckResource(theIconHndl); // Just checkin'...
GetAppParms(theName, &i, &h); // Get the Name of this application
err = MIDISignIn(gSignature, // Use application signature
0L, // Don't need refCon
theIconHndl,
theName); // Use it to name the MIDI client
ReleaseResource(theIconHndl);
if (err)
midiMgrVerNum = 0; // Indicates problem
return err;
}
//--- CMIDIClient::Dispose ----------------------------------------
// Save connections, sign out of MIDI Manager.
//-----------------------------------------------------------------
void CMIDIClient::Dispose(void)
{
if (midiMgrVerNum) // If we are signed in to MM
MIDISignOut(gSignature);
inherited::Dispose(); // Call CObject method
} // It's Miller Time╔
//--- CMIDIClient:: trival methods --------------------------------
MIDIIDListHdl CMIDIClient::GetPorts(void)
{
return (midiMgrVerNum) ? MIDIGetPorts(gSignature) : (MIDIIDListHdl)0;
}
Boolean CMIDIClient::WorldChanged(void)
{
return (midiMgrVerNum) ? MIDIWorldChanged(gSignature) : FALSE;
}
unsigned long CMIDIClient::GetVerNum(void)
{
return midiMgrVerNum;
}
unsigned short CMIDIClient::GetShortVerNum(void)
{
register unsigned long version = midiMgrVerNum;
version >>= 16;
return (unsigned short) version;
}
// end of CMIDIClient.c